package com.usian.article.controller;

import com.usian.apis.article.ApArticleControllerApi;
import com.usian.article.service.ApArticleService;
import com.usian.model.article.ApArticle;
import com.usian.model.article.dto.ArticleHomeDto;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController implements ApArticleControllerApi {
    @Autowired
    private ApArticleService articleService;

    @PostMapping("save")
    @Override
    public ApArticle saveArticle(@RequestBody ApArticle apArticle) {
        articleService.save(apArticle);
        return apArticle;
    }

    /**
     * app  首页查询列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @Override
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)1,dto);
    }

    /**
     * 上拉加载更多  首页查询列表
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    @Override
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)1,dto);
    }

    /**
     * 下拉刷新  首页查询列表
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    @Override
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return articleService.load((short)2,dto);
    }
}
